/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.vsu.cs.piit.vokod.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Галчонок
 */
@Entity
@Table(name = "pacients")
@NamedQueries({
    @NamedQuery(name = "Pacient.findAll", query = "SELECT p FROM Pacient p"),
    @NamedQuery(name = "Pacient.findByPacientId", query = "SELECT p FROM Pacient p WHERE p.pacientId = :pacientId"),
    @NamedQuery(name = "Pacient.findByFio", query = "SELECT p FROM Pacient p WHERE p.fio = :fio"),
    @NamedQuery(name = "Pacient.findByDateOfComing", query = "SELECT p FROM Pacient p WHERE (p.dateOfComing >= :dateOfComing1) and (p.dateOfComing <= :dateOfComing2)"),
    @NamedQuery(name = "Pacient.findByDateOfDischarge", query = "SELECT p FROM Pacient p WHERE (p.dateOfDischarge BETWEEN :dateOfDischarge1 AND :dateOfDischarge2) ORDER BY p.dateOfDischarge"),
    @NamedQuery(name = "Pacient.findByBeddays", query = "SELECT p FROM Pacient p WHERE p.beddays = :beddays"),
    @NamedQuery(name = "Pacient.findByKomplex", query = "SELECT p FROM Pacient p WHERE p.complex = :complex"),
    @NamedQuery(name = "Pacient.findByDateOfEntry", query = "SELECT p FROM Pacient p WHERE p.dateOfEntry = :dateOfEntry"),
    @NamedQuery(name = "Pacient.findByDateOfCorrect", query = "SELECT p FROM Pacient p WHERE p.dateOfCorrect = :dateOfCorrect"),
    @NamedQuery(name = "Pacient.findByDied", query = "SELECT p FROM Pacient p WHERE p.died = :died")})
public class Pacient implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "pacient_id")
    private Integer pacientId;
    @Column(name = "fio")
    private String fio;
    @Column(name = "date_of_coming")
    @Temporal(TemporalType.DATE)
    private Date dateOfComing;
    @Column(name = "date_of_discharge")
    @Temporal(TemporalType.DATE)
    private Date dateOfDischarge;
    @Column(name = "beddays")
    private Integer beddays;
    @Column(name = "komplex")
    private Boolean complex;
    @Column(name = "date_of_entry")
    @Temporal(TemporalType.DATE)
    private Date dateOfEntry;
    @Column(name = "date_of_correct")
    @Temporal(TemporalType.DATE)
    private Date dateOfCorrect;
    @Column(name = "died")
    private Boolean died;
    @Column(name="days_before_treatment")
    private Integer daysBeforeTreatment;

    @JoinColumn(name = "treatment_id", referencedColumnName = "treatment_id")
    @ManyToOne
    private Treatment treatment;

    @JoinColumn(name = "move_to", referencedColumnName = "ward_id")
    @ManyToOne
    private Ward moveTo;

    @JoinColumn(name = "move_from", referencedColumnName = "ward_id")
    @ManyToOne
    private Ward moveFrom;

    @JoinColumn(name = "ward_id", referencedColumnName = "ward_id")
    @ManyToOne(optional = false)
    private Ward ward;

    @JoinColumn(name = "diagnos_id", referencedColumnName = "diagnos_id")
    @ManyToOne
    private Diagnos diagnos;

    public Pacient() {
        dateOfComing = new Date();
        dateOfCorrect = new Date();
        dateOfDischarge = new Date();
        dateOfEntry = new Date();
    }

    public Pacient(Integer pacientId) {
        this.pacientId = pacientId;
    }

    public Integer getPacientId() {
        return pacientId;
    }

    public void setPacientId(Integer pacientId) {
        this.pacientId = pacientId;
    }

    public String getFio() {
        return fio;
    }

    public void setFio(String fio) {
        this.fio = fio;
    }

    public Date getDateOfComing() {
        return dateOfComing;
    }

    public void setDateOfComing(Date dateOfComing) {
        this.dateOfComing = dateOfComing;
    }

    public Date getDateOfDischarge() {
        return dateOfDischarge;
    }

    public void setDateOfDischarge(Date dateOfDischarge) {
        this.dateOfDischarge = dateOfDischarge;
    }

    public Integer getBeddays() {
        return beddays;
    }

    public void setBeddays(Integer beddays) {
        this.beddays = beddays;
    }

    public Boolean getComplex() {
        return complex;
    }

    public void setComplex(Boolean complex) {
        this.complex = complex;
    }

    public Date getDateOfEntry() {
        return dateOfEntry;
    }

    public void setDateOfEntry(Date dateOfEntry) {
        this.dateOfEntry = dateOfEntry;
    }

    public Date getDateOfCorrect() {
        return dateOfCorrect;
    }

    public void setDateOfCorrect(Date dateOfCorrect) {
        this.dateOfCorrect = dateOfCorrect;
    }

    public Boolean getDied() {
        return died;
    }

    public void setDied(Boolean died) {
        this.died = died;
    }

    public Treatment getTreatment() {
        return treatment;
    }

    public void setTreatment(Treatment treatment) {
        this.treatment = treatment;
    }

    public Ward getMoveTo() {
        return moveTo;
    }

    public void setMoveTo(Ward moveTo) {
        this.moveTo = moveTo;
    }

    public Ward getMoveFrom() {
        return moveFrom;
    }

    public void setMoveFrom(Ward moveFrom) {
        this.moveFrom = moveFrom;
    }

    public Ward getWard() {
        return ward;
    }

    public void setWard(Ward ward) {
        this.ward = ward;
    }

    public Diagnos getDiagnos() {
        return diagnos;
    }

    public void setDiagnos(Diagnos diagnosis) {
        this.diagnos = diagnosis;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (pacientId != null ? pacientId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pacient)) {
            return false;
        }
        Pacient other = (Pacient) object;
        if ((this.pacientId == null && other.pacientId != null) || (this.pacientId != null && !this.pacientId.equals(other.pacientId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ru.vsu.cs.vsu.piit.vokod.model.Pacient[pacientId=" + pacientId + "]";
    }

    /**
     * @return the daysBeforeTreatment
     */
    public Integer getDaysBeforeTreatment() {
        return daysBeforeTreatment;
    }

    /**
     * @param daysBeforeTreatment the daysBeforeTreatment to set
     */
    public void setDaysBeforeTreatment(Integer daysBeforeTreatment) {
        this.daysBeforeTreatment = daysBeforeTreatment;
    }

}
